package com.dk.controller;

import com.dk.pojo.SslCourseDetails;
import com.dk.service.SslCourseDetailsService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("course")
public class CourseDetailsController {

    @DubboReference
    private SslCourseDetailsService sslCourseDetailsService;

    @RequestMapping("list")
    public String list(){
        return "/course/list";
    }
    @RequestMapping("getCourse")
    @ResponseBody
    public List<SslCourseDetails> getCourse(){
        return sslCourseDetailsService.selectAll();
    }
    @RequestMapping("toAdd")
    public String toAdd(){
        return "/course/add";
    }
    @RequestMapping("addCourse")
    @ResponseBody
    public boolean addCourse(SslCourseDetails course){
        sslCourseDetailsService.insertCourse(course);
        return true;
    }
    @RequestMapping("toUpdate")
    public String toUpdate(Integer id, Model m){
        SslCourseDetails c = sslCourseDetailsService.selectById(id);
        m.addAttribute("c",c);
        return "/course/update";
    }
    @RequestMapping("updateCourse")
    @ResponseBody
    public boolean updateCourse(SslCourseDetails c){
        sslCourseDetailsService.updateCourse(c);
        return true;
    }
    @RequestMapping("deleteCourse")
    @ResponseBody
    public boolean deleteCourse(Integer id){
        sslCourseDetailsService.deleteById(id);
        return true;
    }
}
